//
//  EZAutoreleasePoolManager.h
//  zhaitu
//
//  Created by ellzu on 13-8-5.
//  Copyright (c) 2013年 ellzu. All rights reserved.
//

#ifndef __zhaitu__EZAutoreleasePoolManager__
#define __zhaitu__EZAutoreleasePoolManager__

#include <iostream>
#include "EZAutoreleasePool.h"
#include "EZTallyDictionary.h"

namespace EZTally {
    
    class EZAutoreleasePoolManager : public EZTallyObject
    {
    private:
//        EZTallyDictionary<long, EZTallyArray<EZAutoreleasePool*>* > *poolsDic;
        std::map<long, std::vector<EZAutoreleasePool*>* > poolsDic;
    protected:
        ~EZAutoreleasePoolManager();
        
        //thread 为空时 自动取当前线程
        std::vector<EZAutoreleasePool*>* PoolsWithThread(pthread_t thread=0);
        bool RemovePoolOnPools(std::vector<EZAutoreleasePool*> *pools,EZAutoreleasePool *pool);
    public:
        EZAutoreleasePoolManager();
        
        static EZAutoreleasePoolManager* DefaultManager();
        
        EZAutoreleasePool* CurrentPool();
        void AddCurrentThreadPool(EZAutoreleasePool* pool);
        void AddPoolToThread(EZAutoreleasePool* pool,pthread_t thread=0);
        void RemovePool(EZAutoreleasePool* pool,pthread_t thread=0);
    };
    
}

#endif /* defined(__zhaitu__EZAutoreleasePoolManager__) */
